<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet" />
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link th:href="@{/erp/assets/css/codemirror.css}" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}" />
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}" />
    <script th:src="@{/erp/assets/js/jquery.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
</head>
<body>
<form>
<div class="add_menber" id="add_menber_style">
    <ul class=" page-content">
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red">*</span>登录帐号：</label>
            <div class="formControls ">
                <input type="text" class="input-text" id="staffUsername" name="staffUsername" onblur="isStaffName()">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red">*</span>初始密码：</label>
            <div class="formControls ">
                <input type="password" class="input-text" id="staffPwd" name="staffPwd">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red">*</span>员工姓名：</label>
            <div class="formControls ">
                <input type="text" class="input-text" id="staffName" name="staffName">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>员工编号：</label>
            <div class="formControls ">
                <input type="text" class="input-text" id="staffId" name="staffId" onblur="isStaffId()">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red">*</span>部门职位：</label>
            <div class="formControls ">
                <select  style="margin-left:10px;" id="deptName" name="deptId">
                    <option value="" selected disabled>--选择部门--</option>
                    <option th:each="dept:${session.dept}"th:value="${dept.id}">
                        [[${dept.deptName}]]
                    </option>
                </select>
                <select style="margin-left:10px;" id="postName" name="postId">
                    <option value="" selected disabled>--选择职位--</option>
                </select>
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>工资科目：</label>
            <div class="formControls ">
                <lable style="width:140px;"><input type="checkbox" name="ids" value="1"  style="width:16px;height:16px;margin-left:10px;"/><span class="1b1" style="margin-left:2px;">基本工资</span></lable>
                <lable style="width:140px;"><input type="checkbox" name="ids" value="2" style="width:16px;height:16px;margin-left:10px;"/><span class="1b1" style="margin-left:2px;">绩效工资</span></lable>
                <lable style="width:140px;"><input type="checkbox" name="ids" value="3" style="width:16px;height:16px;margin-left:10px;"/><span class="1b1" style="margin-left:2px;">加班工资</span></lable>
                <lable style="width:140px;"><input type="checkbox" name="ids" value="4" style="width:16px;height:16px;margin-left:10px;"/><span class="1b1" style="margin-left:2px;">补助资金</span></lable>
                <lable style="width:140px;"><input type="checkbox" name="ids" value="5" style="width:16px;height:16px;margin-left:10px;"/><span class="1b1" style="margin-left:2px;">五险一金</span></lable>
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>联系电话：</label>
            <div class="formControls ">
                <input type="text" class="input-text" id="tel" placeholder="" name="staffTel" onblur="isTel()">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>入职时间：</label>
            <div class="formControls ">
                <input type="date" class="input-text laydate-icon" id="start" name="staffEntry">
            </div>
        </div>

        <div class="">
            <div class="" style=" text-align:center">
                <input class="btn btn-primary radius" id="tijiao" type="submit" value="保存" >
                <input class="btn btn-primary radius" id="tijiao1" type="reset" value="取消">
            </div>
        </div>

    </ul>
</div>
</form>
<script>


    function isTel(){
        var s =$("#tel").val();
        if(!(/^1[3456789]\d{9}$/.test(s))){
            layer.msg("手机号码有误，请重填", {icon: 2});
            return false;
        }
    }

    function isStaffId(){
        var staffId = $("#staffId").val();
        $.ajax({
            type:"get",
            url:"/staff/isStaffId",
            data:{"staffId":staffId},
            success:function (res) {
                if (res.rs) {

                } else {
                    layer.msg("员工编号已存在", {icon: 2});
                }
            }
        })
    }

    function isStaffName(){
        var staffName = $("#staffUsername").val();
        //&lt;![CDATA[
        var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
        //]]>
        if (reg.test(staffName))
        {
            layer.msg("请输入英文或者数字", {icon: 2});
            return false;
        }else{

        }

        $.ajax({
            type:"get",
            url:"/staff/isStaffName",
            data:{"staffName":staffName},
            success:function (res) {
                if (res.rs) {

                } else {
                    layer.msg("员工账号已存在", {icon: 2});
                }
            }
        })
    }

    $(function () {

        //部门下拉框改变事件
        $("#deptName").change(function () {
            var dept = $("#deptName").val();
            if(dept==""){
                return;
            }
            $.ajax({
                cache:true,
                type:"get",
                url:"/staff/postZhi",
                data:{"deptId":dept},
                success:function (data) {
                    console.log(data);
                    var postId = $("#postName").empty();
                    for(var i=0;i<data.length;i++){
                        postId.append("<option value='"+data[i]["postId"]+"' >"+data[i]["postName"]+"</option>");
                    }
                }
            })
        })




        $('#tijiao').on('click', function () {
            var chk_value =[];
            $('input[name="ids"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数
                chk_value.push($(this).val());//将选中的值添加到数组chk_value中
            });


            var staffUsername = $("#staffUsername").val();
            var staffPwd = $("#staffPwd").val();
            var staffName = $("#staffName").val();
            var staffId = $("#staffId").val();
            var deptName = $("#deptName").val();

            var tel = $("#tel").val();
            var start = $("#start").val();
            if(staffUsername == ""){
                layer.msg("登陆账号不能为空", {icon: 2});
            }else if(staffPwd == ""){
                layer.msg("初始密码不能为空", {icon: 2});
            }else if(staffName == ""){
                layer.msg("员工姓名不能为空", {icon: 2});
            }else if(staffId == ""){
                layer.msg("员工编号不能为空", {icon: 2});
            }else if(deptName == null){
                layer.msg("部门职位不能为空", {icon: 2});
            }else if(tel ==""){
                layer.msg("联系电话不能为空", {icon: 2});

            }else if(start ==""){
                layer.msg("入职时间不能为空", {icon: 2});

            }else{
                var s =$("#tel").val();
                if(!(/^1[3456789]\d{9}$/.test(s))){
                    parent.layer.msg("手机号码有误，请重填", {icon: 2});
                    return false;
                }else{
                var data = $('form').serialize();
                $.post('/staff/add', data + '&status='+chk_value, function (res) {
                    if (res.rs) {
                        parent.layer.msg(res.msg, {icon: 1});
                        $('#likeSelect',parent.window.document).click();
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭

                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                });
                }
            }



            return false;
        });
        $('#tijiao1').on('click', function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });




    });
</script>
</body>

</html>